<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>注册</title>
		<link rel="stylesheet" type="text/css" href="../public/bootstrap.min.css"/>
		<script src="../public/jquery-3.5.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../public/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
		<style type="text/css">
			body {
				background-color: #e5e5e5;
			}
			
			.wrap {
				width: 450px;
				margin: 50px auto;
				border: #757575 1px solid;
				padding: 25px;
				border-radius: 5px;
				background-color: #ffffff;
			}
		</style>
	</head>
	<body>
		<div class="wrap">
			<form id="register_form">
				<div class="form-group">
					<label for="exampleInputEmail1">邮箱</label>
					<input type="email" name='email' class="form-control" placeholder="Email">
				</div>
				<div class="form-group">
					<label for="exampleInputPassword1">昵称</label>
					<input type="text" name='id' class="form-control" placeholder="name">
				</div>
				<div class="form-group">
					<label for="exampleInputPassword1">密码</label>
					<input type="password" name='password' class="form-control" placeholder="Password">
				</div>
				<button type="submit" class="btn btn-default">注册</button>
				</br>
				<div class="register">
					<a href="/register">已有账号？点我登录</a>
				</div>
			</form>
		</div>
		<!-- Ajax方法 异步提交 -->
		<!-- <script src="../node_modules/jquery/dist/jquery.js" type="text/javascript" charset="utf-8"></script> -->
		<script type="text/javascript">
			$('#register_form').on('submit',function(e){
				e.preventDefault()
				var formData = $(this).serialize()
				$.ajax({
					url:'/regsssss',
					type:'post',
					data:formData,
					dataType:'json',
					success:function(data){
						var code = data.err_cord
						if(code==500){
							alert('服务忙，请稍后重试')
						}if(code==1){
							alert('该用户已经注册')
						}if(code==0){
							alert('注册成功，请登录')
							//注册成功后直接跳转首页
							window.location.href='/register';
						}
					}
				}) 
			})
		</script>
	</body>
</html>
